use std::collections::HashMap;
use rpc::codec::json_codec::RpcJsonCodec;

macro_rules! create_const {
    ($value:literal, $name:ident) => {
        const $name: &str = $value;
    };
}


#[test]
fn macro_test() {
    // 使用宏创建常量
    create_const!("100", MAX_SIZE);
    create_const!("200", DEFAULT_PORT);
}


macro_rules! call_by_string {
    ($type_name:ty, $method_str:literal) => {
        match $method_str {
            "default" => <$type_name>::default(),
            _ => panic!("Unknown method: {}", $method_str),
        }
    };
}

#[test]
fn macro_test2() {
    let tt = call_by_string!(RpcJsonCodec, "default");
}

// macro_rules! string_to_ty {
//     ($($name:literal => $ty:ty),*) => {
//         $(
//             ($name) => { $ty::default() };
//         )*
//     }
// }
macro_rules! define_type_map {
    ($($name:literal => $ty:ty),*) => {
        macro_rules! string_to_ty {
            $(
                ($name) => { $ty::default() };
            )*
            ($unknown:literal) => {
                compile_error!(concat!("Unknown type string: ", $unknown))
            };
        }
    };
}

#[test]
fn macro_test3() {
    define_type_map!{"json"=>RpcJsonCodec, "bin-code"=>RpcBinCode};
    // let t = string_to_ty!("json");
    // let tt : string_to_ty!("json") = RpcJsonCodec::default();
}

macro_rules! string_to_ty2 {
    ("json")=>{RpcJsonCodec::default()};
    ("bin-code")=>{RpcBinCode::default()};
    ($ unknown:literal)=>{compile_error!(concat!("Unknown type string: ",$unknown))};
}

#[test]
fn macro_test4() {
    let t = string_to_ty2!("json");
    // let tt : string_to_ty!("json") = RpcJsonCodec::default();
}